//渲染页面
function renDer(data){
    //渲染
    appointmentt.innerHTML = "";
    console.log(data);
    data.result.list.forEach((ele,index) => {
        //判断预约是否已满
        let isFull = "可预约";
        appointmentt.innerHTML += `
        <ul data-index=${ele.show_id}>
            <li>${ele.show_name}</li>
            <li>${isFull}</li>
        </ul>
        `;       
    })
}

//正则检查
function check(name,num,card,context){
    //用户正则 
    let regUsername = /^[a-zA-Z0-9_\u4e00-\u9fa5]{2,16}$/;
     //手机正则
    let regNum =/^1[3-9]\d{9}$/;
    //身份证正则
    let regMailbox = /^\d{17}[0-9x]$/;
    
    let n = regUsername.test(name);
    let m = regNum.test(num);
    let c = regMailbox.test(card);

    console.log(context);
    context.classList.add('context');
    if(n == false && m == false && c == false){
        context.innerHTML='都不符合';
        return  false;
    }else if(!n){
        context.innerHTML='用户名2-16位，不能有特殊字符';
        return  false;
    }else if(!m){
        context.innerHTML='号码要11位';
        return  false;
    }else if(!c){
        context.innerHTML='身份证不符合';
        return  false;
    }else{
        console.log('ok');
        context.innerHTML='';
        context.classList.remove('context');
        return true;
    }
}

//本地保存
function setLocationStorage(historyname,history){
   return localStorage.setItem(`${historyname}`,JSON.stringify(history));
}

//获取本地保存
function getLocationStorage(historyname){
    // console.log(historyname);
    return localStorage.getItem(`${historyname}`).replace(/\"/g, "");
}

export {renDer,check,setLocationStorage,getLocationStorage}